package com.caiyouxi.user.util;

import com.caiyouxi.user.util.code.SYS;
import com.caiyouxi.user.util.code.USER;
import org.nutz.lang.Strings;

/**
 * Created by Administrator on 2017/11/11.
 */
public class Code {
    public static BaseResp resp(String code, String s, String x) {

        code = code.toUpperCase();
        if (Strings.equalsIgnoreCase(code, "SUCCESS")) {
            return new BaseResp("SUCCESS", "");
        } else if (code.startsWith("SYS_")) {
            if (Strings.equalsIgnoreCase(code, "SYS_PARAMTER_INVALID")) {
                return CyxUtil.buildErrorResp(code, SYS.map().get(code).replaceAll("%s", s));
            } else if (Strings.equalsIgnoreCase(code, "SYS_BUSY")) {
                return CyxUtil.buildErrorResp(code, SYS.map().get(code).replaceAll("%s", s).replaceAll("%x", x));
            } else {
                return CyxUtil.buildErrorResp(code, SYS.map().get(code));
            }
        } else if (code.startsWith("USER_")) {
            if (Strings.equalsIgnoreCase(code, "USER_PARAMTER_MISSING")) {
                return CyxUtil.buildErrorResp(code, USER.map().get(code).replaceAll("%s", s));
            } else if (Strings.equalsIgnoreCase(code, "USER_PARAMTER_FORMAT_ERROR")) {
                return CyxUtil.buildErrorResp(code, USER.map().get(code).replaceAll("%s", s));
            } else if (Strings.equalsIgnoreCase(code, "USER_OBJ_ALREADY_EXISTS")) {
                return CyxUtil.buildErrorResp(code, USER.map().get(code).replaceAll("%s", s));
            } else {
                return CyxUtil.buildErrorResp(code, USER.map().get(code));
            }
        } else {
            return CyxUtil.buildErrorResp("SYS_UNKNOW_ERROR", "未知错误");
        }
    }

    public static BaseResp resp(String code, String s) {
        return resp(code, s, "");
    }

    public static BaseResp resp(String code) {
        return resp(code, "", "");
    }


}
